<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>递归得到某个属性值</title>
  </head>
  <body>
    <script>
      function recursionGetValue(obj, value) {
        let address;
        function getValue(obj, value) {
          if (typeof obj !== "object") return;
          var keys = Object.keys(obj);
          if (obj instanceof Array) {
            for (let index = 0; index < obj.length; index++) {
              const element = obj[index];
              return getValue(element, value);
            }
          }
          for (let index = 0; index < keys.length; index++) {
            const element = obj[keys[index]];
            if (keys[index] === value) {
              address = element;
              return element;
            }
            if (!address) {
              getValue(element, value);
            }
          }
        }
        getValue(obj, value);
        return address;
      }
      const obj = {
        agentOperator: {
          canSeeOrgIds: [],
          manageDeptIds: [],
        },
        agentOrderFlag: false,
        audit: {
          auths: [],
          canSeeOrgIds: [1],
          createdate: "2021-09-27 09:12:29.000",
          dept: {
            id: 101,
          },
          deptId: 101,
          enableFlag: true,
          id: 2685,
          inviteCode: "Evwn",
          jobNo: "113",
          lastModifyDate: "2022-03-04 13:31:44.000",
          manageDeptIds: [],
          name: "崔正泰",
          org: {
            id: 1,
          },
          orgId: 1,
          pages: [],
          staffAppuid: {
            id: 34,
          },
          user: {
            city: "佛山",
            createdate: "2021-09-27 09:12:29.000",
            district: "顺德区",
            hasTradePassword: false,
            headImg:
              "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png",
            id: 1271,
            lastModifyDate: "2022-03-04 15:32:13.000",
            lastStaffId: 4331,
            mobile: "17876387275",
            province: "广东",
            pwdModifyDate: "2021-12-13 10:45:31.000",
            realName: "崔正泰",
            sex: "male",
            userName: "yp_bcCkYR6yaQ",
          },
          userId: 1271,
        },
        auditDate: "2022-03-04 15:10:32.000",
        auditRemark: "22",
        businessType: "SB-Purchase",
        businessTypeString: "SB采购模式",
        commissionStatus: "unableCommission",
        commissionTotal: 0,
        confirmer: {
          canSeeOrgIds: [],
          manageDeptIds: [],
        },
        createTime: "2022-03-04 15:09:47.444",
        createdate: "2022-03-04 15:09:47.000",
        createor: {
          auths: [],
          canSeeOrgIds: [1760],
          createdate: "2022-02-17 13:31:04.000",
          dept: {
            id: 1880,
          },
          deptId: 1880,
          enableFlag: true,
          id: 4331,
          inviteCode: "Efor",
          isCreator: true,
          jobNo: "001",
          lastModifyDate: "2022-02-28 14:03:34.000",
          manageDeptIds: [],
          name: "崔正泰",
          org: {
            id: 1760,
          },
          orgId: 1760,
          pages: [],
          staffAppuid: {
            id: 45,
          },
          user: {
            city: "佛山",
            createdate: "2021-09-27 09:12:29.000",
            district: "顺德区",
            hasTradePassword: false,
            headImg:
              "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png",
            id: 1271,
            lastModifyDate: "2022-03-04 15:32:13.000",
            lastStaffId: 4331,
            mobile: "17876387275",
            province: "广东",
            pwdModifyDate: "2021-12-13 10:45:31.000",
            realName: "崔正泰",
            sex: "male",
            userName: "yp_bcCkYR6yaQ",
          },
          userId: 1271,
        },
        customerName: "工程订单回测",
        customerPhone: "17876387275",
        deliveryWay: "shipping",
        distributionOrg: {},
        docCatalog: "engineeringOrder",
        docCatalogString: "工程订单",
        enclosure: "",
        expectedDeliveryTime: "2022-03-31 15:09:43.000",
        expressOldPrice: 0,
        expressPrice: 0,
        goodsSumAmt: 1442.1,
        goodsSumOriginalAmt: 1442.1,
        hasPostSales: false,
        hasSyncERP: false,
        id: 31221,
        inviteSharePrice: 0,
        inviteStaff: {
          canSeeOrgIds: [],
          manageDeptIds: [],
        },
        lastModifier: {
          auths: [],
          canSeeOrgIds: [1],
          createdate: "2021-09-27 09:12:29.000",
          dept: {
            id: 101,
          },
          deptId: 101,
          enableFlag: true,
          id: 2685,
          inviteCode: "Evwn",
          jobNo: "113",
          lastModifyDate: "2022-03-04 13:31:44.000",
          manageDeptIds: [],
          name: "崔正泰",
          org: {
            id: 1,
          },
          orgId: 1,
          pages: [],
          staffAppuid: {
            id: 34,
          },
          user: {
            city: "佛山",
            createdate: "2021-09-27 09:12:29.000",
            district: "顺德区",
            hasTradePassword: false,
            headImg:
              "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png",
            id: 1271,
            lastModifyDate: "2022-03-04 15:32:13.000",
            lastStaffId: 4331,
            mobile: "17876387275",
            province: "广东",
            pwdModifyDate: "2021-12-13 10:45:31.000",
            realName: "崔正泰",
            sex: "male",
            userName: "yp_bcCkYR6yaQ",
          },
          userId: 1271,
        },
        lastModifyDate: "2022-03-04 15:11:12.000",
        oper: {
          auths: [],
          canSeeOrgIds: [1760],
          createdate: "2022-02-17 13:31:04.000",
          dept: {
            id: 1880,
          },
          deptId: 1880,
          enableFlag: true,
          id: 4331,
          inviteCode: "Efor",
          isCreator: true,
          jobNo: "001",
          lastModifyDate: "2022-02-28 14:03:34.000",
          manageDeptIds: [],
          name: "崔正泰",
          org: {
            id: 1760,
          },
          orgId: 1760,
          pages: [],
          staffAppuid: {
            id: 45,
          },
          user: {
            city: "佛山",
            createdate: "2021-09-27 09:12:29.000",
            district: "顺德区",
            hasTradePassword: false,
            headImg:
              "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png",
            id: 1271,
            lastModifyDate: "2022-03-04 15:32:13.000",
            lastStaffId: 4331,
            mobile: "17876387275",
            province: "广东",
            pwdModifyDate: "2021-12-13 10:45:31.000",
            realName: "崔正泰",
            sex: "male",
            userName: "yp_bcCkYR6yaQ",
          },
          userId: 1271,
        },
        orderCategory: "成品家具-共享",
        orderCode: "2022030415094738",
        orderGoodsInfos: [
          {
            confirmReceivingNum: 0,
            customerDesignDetailModel: {},
            defaultSupplierId: 1670,
            delFlag: "0",
            deliverType: "factory",
            deliveredNum: 0,
            fileUrls: [],
            goods: {
              auditStatus: "3",
              buyBox: false,
              goodsAdded: "1",
              goodsBelong: "factory",
              goodsBrand: {
                id: 2522,
              },
              goodsCategory: {
                id: 6432,
              },
              goodsCreateTime: "2019-07-10 13:28:01.000",
              goodsDelflag: "0",
              goodsDeno: "个",
              goodsDetailDesc: "",
              goodsImg:
                "https://ruanzhuang-mall.oss-cn-hangzhou.aliyuncs.com/20190710/201907101744259586b3a3a7dc4ba19bc4655eb7447fd9.png@!thumbnail-rule-352",
              goodsModifiedName: "18665546714",
              goodsModifiedTime: "2019-11-15 08:55:06.000",
              goodsName: "大自然无边界 GS系列 东南亚红檀实木休闲圈椅 KQY",
              goodsNo: "201907101328021",
              goodsPrice: 2822,
              goodsSubtitle: "",
              goodsType: {
                defInstallServiceIds: [89],
                defVolume: 0.58425,
                expandparams: [],
                id: 1559,
                productParams: [],
                typeCreateName: "15915837920",
                typeCreateTime: "2019-04-26 14:05:07.000",
                typeDelflag: "0",
                typeModifiedName: "蒋5883",
                typeModifiedTime: "2021-09-24 12:12:37.000",
                typeName: "家具-凳椅类-休闲椅类型",
                typeNickname: "",
              },
              goodsUptime: "2020-07-03 08:57:02.000",
              id: 7360,
              independent: true,
              mobileDesc: "",
              needAppointment: false,
              productAdd: 1,
              productTotal: 1,
              serviceInfo: "",
              showList: "2",
              supplier: {},
              unit: {
                createdate: "2020-11-13 18:26:00.000",
                id: 22,
                lastModifyDate: "2020-11-13 18:26:00.000",
                mustInt: true,
                name: "个",
              },
            },
            goodsInfo: {
              bagRatio: 1,
              boxRatio: 1,
              buyBox: false,
              clients: ["realStore", "designerStudio", "xsh"],
              colorNumber: "9",
              controlPurchaseCostPriceAuth: "modifiable",
              defaultVolume: 0,
              enableSpecialParam: false,
              erpCode: "Y055870",
              erpStatus: "success",
              goods: {
                auditStatus: "3",
                buyBox: false,
                goodsAdded: "1",
                goodsBelong: "factory",
                goodsBrand: {
                  id: 2522,
                },
                goodsCategory: {
                  id: 6432,
                },
                goodsCreateTime: "2019-07-10 13:28:01.000",
                goodsDelflag: "0",
                goodsDeno: "个",
                goodsDetailDesc: "",
                goodsImg:
                  "https://ruanzhuang-mall.oss-cn-hangzhou.aliyuncs.com/20190710/201907101744259586b3a3a7dc4ba19bc4655eb7447fd9.png@!thumbnail-rule-352",
                goodsModifiedName: "18665546714",
                goodsModifiedTime: "2019-11-15 08:55:06.000",
                goodsName: "大自然无边界 GS系列 东南亚红檀实木休闲圈椅 KQY",
                goodsNo: "201907101328021",
                goodsPrice: 2822,
                goodsSubtitle: "",
                goodsType: {
                  defInstallServiceIds: [89],
                  defVolume: 0.58425,
                  expandparams: [],
                  id: 1559,
                  productParams: [],
                  typeCreateName: "15915837920",
                  typeCreateTime: "2019-04-26 14:05:07.000",
                  typeDelflag: "0",
                  typeModifiedName: "蒋5883",
                  typeModifiedTime: "2021-09-24 12:12:37.000",
                  typeName: "家具-凳椅类-休闲椅类型",
                  typeNickname: "",
                },
                goodsUptime: "2020-07-03 08:57:02.000",
                id: 7360,
                independent: true,
                mobileDesc: "",
                needAppointment: false,
                productAdd: 1,
                productTotal: 1,
                serviceInfo: "",
                showList: "2",
                supplier: {},
                unit: {
                  id: 22,
                  name: "个",
                },
              },
              goodsOpenSpecValues: [
                {
                  delFlag: "0",
                  goodsId: 7360,
                  goodsInfoId: 14922,
                  id: 18334,
                  imgUrl: "",
                  spec: {
                    id: 618,
                    specCreateName: "15915837920",
                    specCreateTime: "2019-04-26 10:35:01.000",
                    specDelflag: "0",
                    specModifiedTime: "2021-09-24 12:12:51.000",
                    specName: "颜色",
                  },
                  specDetail: {
                    id: 2240,
                    specDetailCreateName: "15915837920",
                    specDetailCreateTime: "2019-04-26 11:45:46.000",
                    specDetailDelflag: "0",
                    specDetailModifiedTime: "2021-09-24 12:12:51.000",
                    specDetailName: "可定义1",
                    specId: 618,
                  },
                  specName: "颜色",
                  specValueRemark: "紫檀",
                },
              ],
              goodsPrice: {
                purchasePrice: 1442.1,
                rebateAmt: 0,
                rebateRatio: 0,
                salePrice: 2822,
              },
              has3d: true,
              hasStock: true,
              id: 14922,
              imported: false,
              installServices: [],
              logisticsMode: "物流",
              minimumPurchase: 0,
              packageNumber: "1",
              priceType: "日销款",
              saleCatModel: {
                createDate: "2022-01-21 09:53:41.000",
                enableFlag: true,
                enableSpecialParam: false,
                id: 19,
                lastModifyDate: "2022-02-14 21:44:24.000",
                name: "成品家具-共享",
                qty: 2669,
                remark: "",
                sort: "19",
                specialParamRequiredFlag: false,
                standardFlag: true,
              },
              salePriceControl: true,
              showList: true,
              specialParamRequiredFlag: false,
              specialStore: false,
              specialType: "大家居-标品",
              standardFlag: true,
              supplier: {
                address: "大良街道逢沙村智城路1号20层2001之一",
                authBusinessTypes: [],
                businessTypes: [],
                city: "佛山",
                code: "FSJP",
                contact: "樊碧云",
                createdate: "2021-11-26 09:31:09.000",
                district: "顺德区",
                districtModel: {},
                enableFlag: true,
                id: 1670,
                inviteCode: "Bkfzvnhw",
                inviteOrg: {},
                inviteStaff: {
                  canSeeOrgIds: [],
                  manageDeptIds: [],
                },
                lastModifyDate: "2021-12-27 16:01:32.000",
                logo: "//cdn.nature-home.cn/20211126/fcc6e8b121c64412a74a207189a703bc.jpg",
                mobile: "17000000000",
                name: "佛山浚品贸易有限公司",
                orgType: "战略",
                payableRoute: {},
                province: "广东",
                receivableRoute: {},
                searchNumber: 0,
                shortMessageFlag: false,
                status: "auditing",
                supplyOrg: {},
                supplyScope: "家具",
              },
              supplyCode: "X01",
              supplyDays: 30,
              volume: 0.36,
            },
            goodsInfoNum: 1,
            goodsInfoPrice: 1442.1,
            goodsInfoPriceBase: 1254,
            goodsInfoSalePrice: 2822,
            goodsInfoSumPrice: 1442.1,
            goodsInfoSumSalePrice: 2822,
            goodsInfoValue: 1442.1,
            goodsInfoValueAmt: 1442.1,
            id: 325666,
            originalAmt: 1442.1,
            originalPrice: 1442.1,
            priceType: "日销款",
            purchaseCostPrice: 1003,
            purchaseOrderId: 31221,
            supplyCode: "X01",
          },
        ],
        store: {},
      };
      console.log(recursionGetValue(obj, "businessTypeString"));
    </script>
  </body>
</html>
